application of fermat's theorem